From ec7cb595f69d4dc7775ac71f3c03850513b93aee Mon Sep 17 00:00:00 2001 From: oliskoli Date: Tue, 6 Dec 2005 00:12:50 +0000 Subject: [PATCH] Added "delphi compatibility" unit to project GPSBabelGUI. --- gpsbabel/win32/gui-2/delphi.pas | 93 +++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 gpsbabel/win32/gui-2/delphi.pas diff --git a/gpsbabel/win32/gui-2/delphi.pas b/gpsbabel/win32/gui-2/delphi.pas new file mode 100644 index 000000000..c9c5261c5 --- /dev/null +++ b/gpsbabel/win32/gui-2/delphi.pas @@ -0,0 +1,93 @@ +unit delphi; + +// Delpi compatibility unit // + +interface + +uses + SysUtils, TypInfo; + +{$IFDEF VER120} +function GetPropInfo(Instance: TObject; const PropertyName: string): PPropInfo; overload; +function GetPropInfo(Instance: TObject; const Name: string; var PropInfo: TPropInfo): Boolean; overload; +function GetObjectProp(Instance: TObject; Info: PPropInfo): TObject; +function GetStrProp(Instance: TObject; const Name: string): string; overload; +function GetStrProp(Instance: TObject; Info: PPropInfo): string; overload; +procedure SetStrProp(Instance: TObject; const Name, Value: string); overload; +procedure SetStrProp(Instance: TObject; Info: PPropInfo; const Value: string); overload; +{$ENDIF} + +implementation + +{$IFDEF VER120} +function GetPropInfo(Instance: TObject; const PropertyName: string): PPropInfo; +begin + Result := TypInfo.GetPropInfo(Instance.ClassInfo, PropertyName); +end; + +function GetObjectProp(Instance: TObject; Info: PPropInfo): TObject; +begin + Result := Pointer(TypInfo.GetOrdProp(Instance, Info)); +end; + +function GetPropInfo(Instance: TObject; const Name: string; var PropInfo: TPropInfo): Boolean; +var + Props: PPropList; + TypeData: PTypeData; + Info: PPropInfo; + i: Integer; +begin + TypeData := GetTypeData(Instance.ClassInfo); + if ((TypeData <> nil) and (TypeData.PropCount > 0)) then + begin + GetMem(Props, TypeData.PropCount * SizeOf(Pointer)); + try + GetPropInfos(Instance.ClassInfo, Props); + for i := 0 to TypeData.PropCount - 1 do + begin + Info := Props[i]; + if (CompareText(Info.Name, Name) = 0) then + begin + PropInfo := Info^; + Result := True; + Exit; + end + end; + finally + FreeMem(Props); + end; + end; + Result := False; +end; + +function GetStrProp(Instance: TObject; Info: PPropInfo): string; +begin + Result := TypInfo.GetStrProp(Instance, Info); +end; + +function GetStrProp(Instance: TObject; const Name: string): string; +var + Info: TPropInfo; +begin + if GetPropInfo(Instance, Name, Info) then + Result := TypInfo.GetStrProp(Instance, @Info) + else + Result := ''; +end; + +procedure SetStrProp(Instance: TObject; const Name, Value: string); +var + Info: TPropInfo; +begin + if GetPropInfo(Instance, Name, Info) then + SetStrProp(Instance, @Info, Value); +end; + +procedure SetStrProp(Instance: TObject; Info: PPropInfo; const Value: string); +begin + TypInfo.SetStrProp(Instance, Info, Value); +end; + +{$ENDIF} + +end. -- 2.30.2